package com.thh.project.job;


import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;

@Component
@Slf4j
public class JobTest   {

    @Scheduled(cron = "0/5 * * * * *")
    protected void executeInternal()  {
      /*  long currentTime = System.currentTimeMillis();
        log.info("开始执行定时任务");
        try {
            for (int i = 0; i < 100000; i++) {
                i++;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        log.info("定时任务执行完成,耗时：{}", System.currentTimeMillis() - currentTime);*/
        task();
    }


    @Async("taskExecutor")
    public void task(){
        String name = Thread.currentThread().getName();
        System.out.println("线程名称 = " + name);
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }



}